<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

class AuthGroup_m extends FOX_Model
{

	function __construct ()
	{
		parent::__construct();
	}

	public function get_all_groups($status = null){
        $this->db->select('*');
        if(!empty($status)){
            $this->db->where('status',$status);
        }
        $this->db->from('auth_groups');
        $query = $this->db->get();
        if($query->num_rows() > 0){
            return $query->result_array();
        }
    }

    public function get_group_by_id($id){
        $query = $this->db
            ->select('*')
            ->get_where('auth_groups', array('id'=>$id));
        return $query->row_array();
    }

    public function sava_group_rule($uid,$data){

        $this->db->where('id',$uid);
        $this->db->update('auth_groups', $data);
        return ($this->db->affected_rows() > 0) ? TRUE : FALSE;
    }

    public function add_group_rule($data){

        $this->db->insert('auth_groups',$data);
        return ($this->db->affected_rows() > 0) ? TRUE : FALSE;
    }

    public function is_user_group_able($group_id){
        $query = $this->db
            ->select('status')
            ->from('auth_groups')
            ->where('id',$group_id)
            ->get();
        $ulock = $query->row_array();
        if($ulock['status']==1){
            return true;
        }else{
            return false;
        }

    }

}
